package com.china08.yxyapi.repository.db.lectureresult;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.china08.yxyapi.entity.db.huodong.lecture.YxyHuodongLectureResultSchool;

public interface YxyHuodongLectureResultSchoolRepository extends JpaRepository<YxyHuodongLectureResultSchool, String> {

    YxyHuodongLectureResultSchool findBySchoolId(String schoolId);

    Page<YxyHuodongLectureResultSchool> findByAreaIdDistrictAndSchoolNickContaining(String areaId, String schoolName,
            Pageable pageable);

    Page<YxyHuodongLectureResultSchool> findByAreaIdDistrict(String areaId, Pageable pageable);

    Page<YxyHuodongLectureResultSchool> findBySchoolNickContaining(String schoolName, Pageable pageable);

    List<YxyHuodongLectureResultSchool> findTop20ByAreaIdDistrictOrderByPackCountDesc(String areaId);

    Integer countByAreaIdDistrict(String areaId);

    @Transactional(readOnly = true)
    @Query(value = "SELECT COALESCE(SUM(pack_count),0) FROM yxy_huodong.yxy_huodong_lecture_result_school WHERE area_id_district=?1 ", nativeQuery = true)
    Integer countAll(String code);

}